#include<iostream>
#include<algorithm>
using namespace std;
struct Stu{
	int name;
	int chinese;
	int math;
	int english;
	int total ;
}arr[400];
bool cmp(struct Stu s1,struct Stu s2){
	if(s1.total != s2.total)
	return s1.total > s2.total;
	else if(s1.total == s2.total)
	{
		if(s1.chinese != s2.chinese)
		{
			return s1.chinese > s2.chinese;
		}
		else if(s1.chinese == s2.chinese)
		{
			if(s1.math != s2.math)
			{
				return s1.math > s2.math;
			}
			else if(s1.math == s2.math)
			{
				if(s1.english != s2.english)
				{
					return s1.english > s2.english;
				}
				else if(s1.english == s2.english)
				{
					return s1.name > s2.name;
				}
			}
		}
	}
}
int main(){
	int n;
	cin >> n;
	for(int i = 0 ; i < n ;i++){
		cin  >> arr[i].chinese >> arr[i].math >> arr[i].english;
		arr[i].name = i + 1;
		arr[i].total = arr[i].chinese + arr[i].english + arr[i].math;
	}
	sort(arr, arr + n, cmp);
	for(int i = 0 ; i < 5; i++)
	{
		cout << arr[i].name << ' ' << arr[i].total << endl;
	}
	return 0;
}
